package logic

import (
	"context"
	"shuqi-novel/model/mysql"

	"shuqi-novel/userrpc/internal/svc"
	"shuqi-novel/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type NovelAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewNovelAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NovelAddLogic {
	return &NovelAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 小说添加
func (l *NovelAddLogic) NovelAdd(in *userrpc.NovelAddRequest) (*userrpc.NovelAddResponse, error) {
	// todo: add your logic here and delete this line

	novel := mysql.Novel{
		NovelTitle:   in.NovelTitle,
		NovelContent: in.NovelContent,
		NovelStyle:   in.NovelStyle,
	}
	err := novel.NovelAdd(mysql.DB)
	if err != nil {
		return nil, err
	}

	return &userrpc.NovelAddResponse{
		NovelId: int64(novel.ID),
	}, nil
}
